package org.siqisource.webstart.core.widgets.tree.ztree.service;

import java.util.List;

import org.siqisource.webstart.core.utils.condition.Condition;
import org.siqisource.webstart.core.widgets.tree.config.TreeConfig;
import org.siqisource.webstart.core.widgets.tree.model.TreeNode;
import org.siqisource.webstart.core.widgets.tree.service.TreeDragAndDropService;
import org.siqisource.webstart.core.widgets.tree.service.TreeService;
import org.siqisource.webstart.core.widgets.tree.ztree.helper.ZtreeHelper;
import org.siqisource.webstart.core.widgets.tree.ztree.model.ZtreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ZtreeService {
	
	@Autowired
	TreeService treeService;
	
	@Autowired
	TreeDragAndDropService treeDragAndDropService;
	
	 
	
	public List<ZtreeNode> readChildren(TreeConfig treeConfig, Integer parentNodeId, Condition condition) {
		List<TreeNode> treeNodes =  treeService.readChildren(treeConfig, parentNodeId, condition);
		return ZtreeHelper.getZtreeNodeList(treeNodes);
	}
	
	public List<ZtreeNode> readChildren(TreeConfig treeConfig, Integer parentNodeId) {
		return this.readChildren(treeConfig, parentNodeId,null);
	}
	
	public Integer insertNode(TreeConfig treeConfig, Object node) {
		return this.treeService.insertNode(treeConfig, node);
	}
	
	public void deleteTreeNodeCascade(TreeConfig treeConfig, Integer id) {
		this.treeService.deleteTreeNodeCascade(treeConfig, id);
	}
}
